package hadoop.ch03.v17034460231;

import org.apache.hadoop.conf.*;
import org.apache.hadoop.fs.*;

import java.net.URI;

public class CreateHDFSFile {
    public static void main (String[] args) throws  Exception{
        Configuration conf = new Configuration();
        URI uri = new URI("hdfs://192.168.30.131:8020");   // 配置NameNode地址
        FileSystem fs = FileSystem.get(uri,conf,"hadoop");  // 指定用户名,获取FileSystem对象
        Path dfs = new Path("/17034460231/test2.txt"); //定义文件路径
        FSDataOutputStream os = fs.create(dfs ,true);
        os.writeBytes("hello,hdfs!");  //往文件写入信息
        os.close(); //关闭流
        fs.close(); //关闭FileSystem
    }
}
